/**
 * 重置琴谱
 */
function resetScore() {
    $('#trackdetail').css({ 'left': pianoCodeLength });   //重置琴谱
    $('.note').removeClass('noteactive');              //重置琴谱状态
}

/**
 * 随机生成字符串
 * @param {*} len 
 */
function randomStr(len) {
    let str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', result = '';

    for (let i = len; i > 0; --i) {
        result += str[Math.floor(Math.random() * str.length)];
    }

    return new Date().getTime() + result;
}

/**
 * 模拟按键
 * @param k 按下的按键对应的key值
 */
function simulationKeydown(k) {
    let e = jQuery.Event("keydown"), u = jQuery.Event("keyup"), tmp = [];

    if (typeof k == 'object') {
        //组合按键
        for (let i in k) {
            e.keyCode = k[i];
            tmp.push(k[i]);

            $(window).trigger(e);//按键按下
        }
        setTimeout(function () {
            for (let a in tmp) {
                u.keyCode = tmp[a];

                $(window).trigger(u);//按键弹起
            }
        }, 50);
    } else {
        //单按键
        e.keyCode = k;
        u.keyCode = k;

        $(window).trigger(e);//按键按下
        setTimeout(function () {
            $(window).trigger(u);//按键弹起
        }, 50);
    }
}
